from typing import Optional
from langchain_deepseek import ChatDeepSeek
from pydantic import BaseModel, Field
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)

llm = ChatDeepSeek(
    model="deepseek-chat",  # 模型名称
    temperature=0,         # 控制生成随机性(0-1)
    max_tokens=None,       # 最大输出token数
    timeout=None,          # 超时设置
    max_retries=2,         # 失败重试次数
    api_key="sk-XXXXXXXX"
)

class Joke(BaseModel):
    """Joke to tell user."""

    setup: str = Field(description="The setup of the joke")
    punchline: str = Field(description="The punchline to the joke")
    rating: Optional[int] = Field(
        default=None, description="How funny the joke is, from 1 to 10"
    )
structured_llm = llm.with_structured_output(Joke)
print(structured_llm.invoke("Tell me a joke about cats"))
